package com.lzx.iteam;

import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.drawable.ColorDrawable;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.telephony.PhoneNumberUtils;
import android.text.TextUtils;
import android.text.method.QwertyKeyListener;
import android.text.method.TextKeyListener;
import android.util.Log;
import android.view.*;
import android.widget.ImageButton;
import android.widget.TextView;
import com.lzx.iteam.R;
import com.lzx.iteam.bean.SkinCommonData;
import com.lzx.iteam.bean.SkinVertyData;
import com.lzx.iteam.skin.GetSkinResource;
import com.lzx.iteam.util.Constants;
import com.lzx.iteam.util.PreferenceUtil;
import com.lzx.iteam.widget.DialpadEditText;
import com.lzx.iteam.widget.InterceptFrameLayout;
import com.lzx.iteam.widget.TextImageButton;

import java.util.HashMap;

/**
 * Created by hfx on 15-1-4.
 */
public class KeyboardVertFrag extends Fragment implements SharedPreferences.OnSharedPreferenceChangeListener, View.OnClickListener, View.OnLongClickListener, View.OnTouchListener, View.OnKeyListener {
    public static HashMap<Integer, Integer> mViewIdKeyCodeMap = new HashMap<Integer, Integer>();
    private static final String TAG = "KeyboardVertFrag";
    public String mSearchTextT9 = "";
    public String mSearchTextAllWord = "";

    static {
        mViewIdKeyCodeMap.put(R.id.dial_btn_num1, KeyEvent.KEYCODE_1);
        mViewIdKeyCodeMap.put(R.id.dial_btn_num2, KeyEvent.KEYCODE_2);
        mViewIdKeyCodeMap.put(R.id.dial_btn_num3, KeyEvent.KEYCODE_3);
        mViewIdKeyCodeMap.put(R.id.dial_btn_num4, KeyEvent.KEYCODE_4);
        mViewIdKeyCodeMap.put(R.id.dial_btn_num5, KeyEvent.KEYCODE_5);
        mViewIdKeyCodeMap.put(R.id.dial_btn_num6, KeyEvent.KEYCODE_6);
        mViewIdKeyCodeMap.put(R.id.dial_btn_num7, KeyEvent.KEYCODE_7);
        mViewIdKeyCodeMap.put(R.id.dial_btn_num8, KeyEvent.KEYCODE_8);
        mViewIdKeyCodeMap.put(R.id.dial_btn_num9, KeyEvent.KEYCODE_9);
        mViewIdKeyCodeMap.put(R.id.dial_btn_num0, KeyEvent.KEYCODE_0);

        mViewIdKeyCodeMap.put(R.id.dial_btn_num_h_1, KeyEvent.KEYCODE_1);
        mViewIdKeyCodeMap.put(R.id.dial_btn_num_h_2, KeyEvent.KEYCODE_2);
        mViewIdKeyCodeMap.put(R.id.dial_btn_num_h_3, KeyEvent.KEYCODE_3);
        mViewIdKeyCodeMap.put(R.id.dial_btn_num_h_4, KeyEvent.KEYCODE_4);
        mViewIdKeyCodeMap.put(R.id.dial_btn_num_h_5, KeyEvent.KEYCODE_5);
        mViewIdKeyCodeMap.put(R.id.dial_btn_num_h_6, KeyEvent.KEYCODE_6);
        mViewIdKeyCodeMap.put(R.id.dial_btn_num_h_7, KeyEvent.KEYCODE_7);
        mViewIdKeyCodeMap.put(R.id.dial_btn_num_h_8, KeyEvent.KEYCODE_8);
        mViewIdKeyCodeMap.put(R.id.dial_btn_num_h_9, KeyEvent.KEYCODE_9);
        mViewIdKeyCodeMap.put(R.id.dial_btn_num_h_0, KeyEvent.KEYCODE_0);

        mViewIdKeyCodeMap.put(R.id.dial_btn_A, KeyEvent.KEYCODE_A);
        mViewIdKeyCodeMap.put(R.id.dial_btn_B, KeyEvent.KEYCODE_B);
        mViewIdKeyCodeMap.put(R.id.dial_btn_C, KeyEvent.KEYCODE_C);
        mViewIdKeyCodeMap.put(R.id.dial_btn_D, KeyEvent.KEYCODE_D);
        mViewIdKeyCodeMap.put(R.id.dial_btn_E, KeyEvent.KEYCODE_E);
        mViewIdKeyCodeMap.put(R.id.dial_btn_F, KeyEvent.KEYCODE_F);
        mViewIdKeyCodeMap.put(R.id.dial_btn_G, KeyEvent.KEYCODE_G);
        mViewIdKeyCodeMap.put(R.id.dial_btn_H, KeyEvent.KEYCODE_H);
        mViewIdKeyCodeMap.put(R.id.dial_btn_I, KeyEvent.KEYCODE_I);
        mViewIdKeyCodeMap.put(R.id.dial_btn_J, KeyEvent.KEYCODE_J);
        mViewIdKeyCodeMap.put(R.id.dial_btn_K, KeyEvent.KEYCODE_K);
        mViewIdKeyCodeMap.put(R.id.dial_btn_L, KeyEvent.KEYCODE_L);
        mViewIdKeyCodeMap.put(R.id.dial_btn_M, KeyEvent.KEYCODE_M);
        mViewIdKeyCodeMap.put(R.id.dial_btn_N, KeyEvent.KEYCODE_N);
        mViewIdKeyCodeMap.put(R.id.dial_btn_O, KeyEvent.KEYCODE_O);
        mViewIdKeyCodeMap.put(R.id.dial_btn_P, KeyEvent.KEYCODE_P);
        mViewIdKeyCodeMap.put(R.id.dial_btn_Q, KeyEvent.KEYCODE_Q);
        mViewIdKeyCodeMap.put(R.id.dial_btn_R, KeyEvent.KEYCODE_R);
        mViewIdKeyCodeMap.put(R.id.dial_btn_S, KeyEvent.KEYCODE_S);
        mViewIdKeyCodeMap.put(R.id.dial_btn_T, KeyEvent.KEYCODE_T);
        mViewIdKeyCodeMap.put(R.id.dial_btn_U, KeyEvent.KEYCODE_U);
        mViewIdKeyCodeMap.put(R.id.dial_btn_V, KeyEvent.KEYCODE_V);
        mViewIdKeyCodeMap.put(R.id.dial_btn_W, KeyEvent.KEYCODE_W);
        mViewIdKeyCodeMap.put(R.id.dial_btn_X, KeyEvent.KEYCODE_X);
        mViewIdKeyCodeMap.put(R.id.dial_btn_Y, KeyEvent.KEYCODE_Y);
        mViewIdKeyCodeMap.put(R.id.dial_btn_Z, KeyEvent.KEYCODE_Z);
        mViewIdKeyCodeMap.put(R.id.btn_delete, KeyEvent.KEYCODE_DEL);
        mViewIdKeyCodeMap.put(R.id.dial_btn_xing, KeyEvent.KEYCODE_STAR);
        mViewIdKeyCodeMap.put(R.id.dial_btn_h_xing, KeyEvent.KEYCODE_STAR);
    }

    // 竖向T9键盘
    private TextImageButton mView_v_num1;
    private TextImageButton mView_v_num2;
    private TextImageButton mView_v_num3;
    private TextImageButton mView_v_num4;
    private TextImageButton mView_v_num5;
    private TextImageButton mView_v_num6;
    private TextImageButton mView_v_num7;
    private TextImageButton mView_v_num8;
    private TextImageButton mView_v_num9;
    private TextImageButton mView_v_num0;
    private TextImageButton mView_v_num_del;
    private TextImageButton mView_v_num_star;
    private TextImageButton mView_v_num_dial;
    private TextImageButton mView_v_num_sms;
    private ImageButton mBtnDial;
    private TextImageButton mView_v_dial;


    // 竖向全字母键盘
    private TextImageButton mView_v_wordA;
    private TextImageButton mView_v_wordB;
    private TextImageButton mView_v_wordC;
    private TextImageButton mView_v_wordD;
    private TextImageButton mView_v_wordE;
    private TextImageButton mView_v_wordF;
    private TextImageButton mView_v_wordG;
    private TextImageButton mView_v_wordH;
    private TextImageButton mView_v_wordI;
    private TextImageButton mView_v_wordJ;
    private TextImageButton mView_v_wordK;
    private TextImageButton mView_v_wordL;
    private TextImageButton mView_v_wordM;
    private TextImageButton mView_v_wordN;
    private TextImageButton mView_v_wordO;
    private TextImageButton mView_v_wordP;
    private TextImageButton mView_v_wordQ;
    private TextImageButton mView_v_wordR;
    private TextImageButton mView_v_wordS;
    private TextImageButton mView_v_wordT;
    private TextImageButton mView_v_wordU;
    private TextImageButton mView_v_wordV;
    private TextImageButton mView_v_wordW;
    private TextImageButton mView_v_wordX;
    private TextImageButton mView_v_wordY;
    private TextImageButton mView_v_wordZ;
    private TextImageButton mView_v_word_del;


    private View mKeyVert;
    private ViewStub mT9viewSub;
    private ViewStub mABCviewSub;
    private CloudDialerActivity mActivity;
    private PreferenceUtil mPreferenceUtil;
    public boolean mKeypadAtRight;  //当前键盘是否在右边,默认为右边
    public boolean mIsT9 = false;    // 当前为全键盘或者T9键盘，默认情况下为T9键盘
    private int mIsHaveTone;  //皮肤是否包含声音
    private InterceptFrameLayout mKeyboardeVertical;
    public SkinVertyData mSkin; //竖键盘皮肤数据
    public SkinCommonData mSkinCommonData; //公共皮肤数据
    private boolean IsInflateT9 = false;
    private boolean IsInflateWords = false;

    private View mT9DialPad;
    private View mAllWordPad;

    private DialpadEditText mDigits;
    public TextImageButton mChangeDialPadT9_vertical_right;
    public TextImageButton mChangeDialPadT9_vertical_left;
    private TextImageButton mBtnSendMsg;
    private TextView mBtnDialTextShowArea;

    public DialpadEditText mDigits_words_vertical;
    public TextImageButton mChangeDialPadAllWord_vertical_right;
    public TextImageButton mChangeDialPadAllWord_vertical_left;
    private GetSkinResource mResource;
    private boolean mNeedReloadSkin = false;

    public static KeyboardVertFrag newInstance(Bundle args) {
        KeyboardVertFrag f = new KeyboardVertFrag();
        f.setArguments(args);
        return f;
    }


    @Override
    public void onResume() {
        super.onResume();
        Log.d("KeyboardeVertical"," KeyboardeVertical  =====  onResume");
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Log.d("KeyboardeVertical"," KeyboardeVertical  =====  onCreate");
        mActivity = (CloudDialerActivity) getActivity();
        mPreferenceUtil = PreferenceUtil.getInstance(mActivity);
        mKeypadAtRight = mPreferenceUtil.getBoolean(PreferenceUtil.KEYPAD_AT_RIGHT, true);
        mKeypadAtRight = mPreferenceUtil.getBoolean(PreferenceUtil.KEYPAD_AT_RIGHT, true);
        Log.e("eeeeeeeeee","public void onCreate(Bundle savedInstanceState)");
        mIsT9 = mPreferenceUtil.getBoolean(PreferenceUtil.IS_T9, false);//若注释掉则不可切换
        mIsHaveTone = mPreferenceUtil.getInt(PreferenceUtil.CONTACT_IS_HAVESOUND,
                Constants.SOUND_CLOSE);

        mPreferenceUtil.registerOnSharedPreferenceChangeListener(PreferenceUtil.KEYPAD_AT_RIGHT,
                this);
    }

    public void formatDigitInput(Intent i) {
        if(i == null){
            return;
        }
        String action = i.getAction();
        Uri data = i.getData();
        if (Intent.ACTION_VIEW.equals(action)) {
            Uri uri = data;
            if (uri != null && "tel".equals(uri.getScheme())) {
                // Put the requested number into the input area
                String dataStr = uri.getSchemeSpecificPart();
                changeKeyBoard2FitDial();
                setFormattedDigits(dataStr);
            }
        } else if (Intent.ACTION_DIAL.equals(action)) {
            Uri uri = data;
            if (uri != null && "tel".equals(uri.getScheme())) {
                // Put the requested number into the input area
                String dataStr = uri.getSchemeSpecificPart();

                changeKeyBoard2FitDial();
                setFormattedDigits(dataStr);
            }
        }
    }

    public void changeKeyBoard2FitDial() {
        if (!mIsT9) {
            mIsT9 = true;
            switchKeyboard(mIsT9, mSkin, false);
//            mPreferenceUtil.save(PreferenceUtil.IS_T9_KEYBOARD_STATUS, mIsT9_hort);
            Log.e("eeeeeeeeee","changeKeyBoard2FitDial");
        }
    }

    protected void setFormattedDigits(String data) {
        // strip the non-dialable numbers out of the data string.
        String dialString = PhoneNumberUtils.extractNetworkPortion(data);
        dialString = PhoneNumberUtils.formatNumber(dialString);
        if (!TextUtils.isEmpty(dialString)) {
            setFilterText(dialString);
        }
    }

    public void changeSkin(SkinVertyData skin, SkinCommonData commonData) {
        initAllSkin(skin, commonData);
    }

    private void initAllSkin(SkinVertyData skin, SkinCommonData commonData) {
        boolean isT9 = mPreferenceUtil.getBoolean(PreferenceUtil.IS_T9, true);
        mSkinCommonData = commonData;
        mSkin = skin;
        if(isT9){
            initAllwordsLayout(skin, commonData);
            initT9Layout(skin, commonData);
            if (mT9DialPad != null)
                mT9DialPad.setVisibility(View.VISIBLE);
            if (mAllWordPad != null)
                mAllWordPad.setVisibility(View.GONE);
        }else{
            initT9Layout(skin, commonData);
            initAllwordsLayout(skin, commonData);
            if (mT9DialPad != null)
                mT9DialPad.setVisibility(View.GONE);
            if (mAllWordPad != null)
                mAllWordPad.setVisibility(View.VISIBLE);
        }

    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        Log.d("KeyboardeVertical"," KeyboardeVertical  =====  onCreateView");
        mKeyVert = inflater.inflate(R.layout.key_vert, container, false);
        mKeyboardeVertical = (InterceptFrameLayout) mKeyVert.findViewById(R.id.keypad_vertical);
        mKeyboardeVertical.setOnDoubleScrollListener(new InterceptFrameLayout.DoubleScrollListener() {
            @Override
            public void onDoubleScroll(float dis) {
                //mActivity.scrollVerticalPadView(dis);
            }

            @Override
            public void onDobleScrollUp() {
                //mActivity.saveVerticalKbLastPosition();
            }

        });
        mKeyboardeVertical.setListener(mActivity);
        mKeyboardeVertical.setChangeKeyBordListener(new InterceptFrameLayout.ChangeKeyBordListener(){


            @Override
            public void t9DialPad(String searchText) {
                setSearchTextT9(searchText);
            }

            @Override
            public void allWordPad(String searchText) {
                setSeaechTextAllWord(searchText);
            }
        });
        
        mSkinCommonData = ((CloudDialerActivity) getActivity()).mSkinCommon;
        mT9viewSub = (ViewStub) mKeyVert.findViewById(R.id.viewsub_dialpad);
        mABCviewSub = (ViewStub) mKeyVert.findViewById(R.id.viewsub_allwords);
        

        if (mIsT9) 
        {
        	mSkin = ((CloudDialerActivity) getActivity()).mVertySkin;
        	
            if (!IsInflateT9) {
                IsInflateT9 = true;
                mT9viewSub.inflate();
            }
            initT9Layout(((CloudDialerActivity) getActivity()).mVertySkin, mSkinCommonData);
            
        } 
        else 
        {
        	mSkin = ((CloudDialerActivity) getActivity()).mVertySkin2;
            if (!IsInflateWords) {
                IsInflateWords = true;
                mABCviewSub.inflate();
            }
            initAllwordsLayout(((CloudDialerActivity) getActivity()).mVertySkin2, mSkinCommonData);
        }
        /*
        if (!isloadAbc) {
            isloadAbc = true;
            //mSkin = ((CloudDialerActivity) getActivity()).mVertySkin2;//mResource.getVertABCSkinData(skin, mActivity, path);
            //skin = mSkin;
            initAllwordsLayout(((CloudDialerActivity) getActivity()).mVertySkin2, mSkinCommonData);
        }
		
        if (!isloadT9) {
            isloadT9 = true;
            //mSkin = ((CloudDialerActivity) getActivity()).mVertySkin;//mResource.getVertT9SkinData(skin, mActivity, path);
            //skin = mSkin;
            initT9Layout(((CloudDialerActivity) getActivity()).mVertySkin, mSkinCommonData);
        }
		*/
        
        
        Bundle activityArgs = getArguments();
        if(activityArgs == null){
            Log.i("null","null");
        }
        if (activityArgs.containsKey(CloudDialerActivity.DATA)) {
            formatDigitInput((Intent) activityArgs.getParcelable(CloudDialerActivity.DATA));
            activityArgs.remove(CloudDialerActivity.DATA);
        }
        String input = activityArgs.getString("input");

        Log.d("KeyboardeVertical"," KeyboardeVertical  == onCreateView input == " + input);

        if(input != null){
            setFilterText(input);
        }

        if(!mKeypadAtRight){
            controlDisplayImageButtonForT9OrAllwords(mKeypadAtRight);
        }
        

        switchKeyboard(
                mIsT9, mSkin, false);

        
        return mKeyVert;
    }

    private void initT9Layout(SkinVertyData skin, SkinCommonData commonData) {
        mT9DialPad = mKeyVert.findViewById(R.id.dial_buttons_T9);
        if (mT9DialPad == null) {
            mT9viewSub.inflate();
            IsInflateT9 = true;
            mT9DialPad = mKeyVert.findViewById(R.id.dial_buttons_T9);
        }
        initKeypadVertical();
        initVerticalT9Skin(skin, commonData);
        setupKeypadVertical();
    }

    private void initKeypadVertical() {
        View keyboardRoot = mT9DialPad;

        mChangeDialPadT9_vertical_right = (TextImageButton) keyboardRoot
                .findViewById(R.id.displaypanelT9_right);
        mChangeDialPadT9_vertical_left = (TextImageButton) keyboardRoot
                .findViewById(R.id.displaypanelT9_left);
        // dialpad related
        mDigits = (DialpadEditText) keyboardRoot.findViewById(R.id.digits);
        mDigits.setOnFocusChangeListener(new View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                Log.d(TAG, "mDigits onFocusChange: " + v + " " + hasFocus);
            }
        });

        mBtnDialTextShowArea = (TextView) keyboardRoot.findViewById(R.id.dial_btn_showarea);
        mBtnSendMsg = (TextImageButton) keyboardRoot.findViewById(R.id.dial_btn_send_msg);

        // num0
        mView_v_num0 = (TextImageButton) keyboardRoot.findViewById(R.id.dial_btn_num0);
        // num1
        mView_v_num1 = (TextImageButton) keyboardRoot.findViewById(R.id.dial_btn_num1);
        // num2
        mView_v_num2 = (TextImageButton) keyboardRoot.findViewById(R.id.dial_btn_num2);
        // num3
        mView_v_num3 = (TextImageButton) keyboardRoot.findViewById(R.id.dial_btn_num3);
        // num4
        mView_v_num4 = (TextImageButton) keyboardRoot.findViewById(R.id.dial_btn_num4);
        // num5
        mView_v_num5 = (TextImageButton) keyboardRoot.findViewById(R.id.dial_btn_num5);
        // num6
        mView_v_num6 = (TextImageButton) keyboardRoot.findViewById(R.id.dial_btn_num6);
        // num7
        mView_v_num7 = (TextImageButton) keyboardRoot.findViewById(R.id.dial_btn_num7);
        // num8
        mView_v_num8 = (TextImageButton) keyboardRoot.findViewById(R.id.dial_btn_num8);
        // num9
        mView_v_num9 = (TextImageButton) keyboardRoot.findViewById(R.id.dial_btn_num9);

        mView_v_num_star = (TextImageButton) keyboardRoot.findViewById(R.id.dial_btn_xing);
        mView_v_num_del = (TextImageButton) keyboardRoot.findViewById(R.id.dial_btn_delete);

        //: vert keyboard duplicate?
        mView_v_dial = (TextImageButton) keyboardRoot.findViewById(R.id.dial_btn_dial);
        mBtnDial = (ImageButton) keyboardRoot.findViewById(R.id.dial_btn_dial);
    }

    /**
     * 初始化垂直方向T9 键盘
     */
    public void initVerticalT9Skin(SkinVertyData skin, SkinCommonData commonData) {
        CloudDialerActivity.setBgAndScalType(mView_v_num0, commonData);
        mView_v_num0.setImageDrawable(skin.vt9BgResId[0]);

        CloudDialerActivity.setBgAndScalType(mView_v_num1, commonData);
        mView_v_num1.setImageDrawable(skin.vt9BgResId[1]);

        CloudDialerActivity.setBgAndScalType(mView_v_num2, commonData);
        mView_v_num2.setImageDrawable(skin.vt9BgResId[2]);

        CloudDialerActivity.setBgAndScalType(mView_v_num3, commonData);
        mView_v_num3.setImageDrawable(skin.vt9BgResId[3]);

        CloudDialerActivity.setBgAndScalType(mView_v_num4, commonData);
        mView_v_num4.setImageDrawable(skin.vt9BgResId[4]);

        CloudDialerActivity.setBgAndScalType(mView_v_num5, commonData);
        mView_v_num5.setImageDrawable(skin.vt9BgResId[5]);

        CloudDialerActivity.setBgAndScalType(mView_v_num6, commonData);
        mView_v_num6.setImageDrawable(skin.vt9BgResId[6]);

        CloudDialerActivity.setBgAndScalType(mView_v_num7, commonData);
        mView_v_num7.setImageDrawable(skin.vt9BgResId[7]);

        CloudDialerActivity.setBgAndScalType(mView_v_num8, commonData);
        mView_v_num8.setImageDrawable(skin.vt9BgResId[8]);

        CloudDialerActivity.setBgAndScalType(mView_v_num9, commonData);
        mView_v_num9.setImageDrawable(skin.vt9BgResId[9]);

        CloudDialerActivity.setBgAndScalType(mBtnDial, commonData);
        mBtnDial.setImageDrawable(skin.vcallResId);

        mDigits.setBackgroundDrawable(skin.vInputResId);
//        mDigits.setTextColor(commonData.barTitleColor);
        mDigits.setTextColor(getResources().getColor(R.color.white));

        // mChangeDialPadT9_vertical_right.setBackgroundColor(skin.backgroundColor);
        CloudDialerActivity.setBgAndScalType(mChangeDialPadT9_vertical_right, commonData);
        mChangeDialPadT9_vertical_right.setImageDrawable(skin.vAndAbcResId_normal);
        mChangeDialPadT9_vertical_right.setColor(commonData.barTitleColor);

        mT9DialPad.setBackgroundDrawable(new ColorDrawable(commonData.backgroundColor));
        // mKeyboardeVertical.setBackgroundDrawable(new
        // ColorDrawable(skin.backgroundColor));

        CloudDialerActivity.setBgAndScalType(mChangeDialPadT9_vertical_left, commonData);
        mChangeDialPadT9_vertical_left.setImageDrawable(skin.vAndAbcResId_normal);
        mChangeDialPadT9_vertical_left.setColor(commonData.barTitleColor);

        CloudDialerActivity.setBgAndScalType(mView_v_dial, commonData);
        mView_v_dial.setImageDrawable(skin.vcallResId);

        CloudDialerActivity.setBgAndScalType(mView_v_num_star, commonData);
        mView_v_num_star.setImageDrawable(skin.vstarResId);

        CloudDialerActivity.setBgAndScalType(mView_v_num_del, commonData);
        mView_v_num_del.setImageDrawable(skin.vt9delResId);

        CloudDialerActivity.setBgAndScalType(mBtnSendMsg, commonData);
        mBtnSendMsg.setImageDrawable(skin.vsmsResId);

        mBtnDialTextShowArea.setTextColor(commonData.barTitleColor);
    }

    private void initAllwordsLayout(SkinVertyData skin, SkinCommonData commonData) {
        mAllWordPad = mKeyVert.findViewById(R.id.dial_buttons_allwords);
        if (mAllWordPad == null) {
            mABCviewSub.inflate();
            IsInflateWords = true;
            mAllWordPad = mKeyVert.findViewById(R.id.dial_buttons_allwords);
        }
        initKeypadPortraitAllwords();
        initVerticalAllwordsSkin(skin, commonData);
        setupKeypadPortraitAllwords();
    }

    private void initKeypadPortraitAllwords() {
        View keyboardRoot = mAllWordPad;

        mDigits_words_vertical = (DialpadEditText) keyboardRoot
                .findViewById(R.id.digits_words_vertical);
        mDigits_words_vertical.setOnFocusChangeListener(new View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                Log.d(TAG, "mDigits_words_vertical onFocusChange: " + v + " " + hasFocus);
            }
        });

        mChangeDialPadAllWord_vertical_right = (TextImageButton) keyboardRoot
                .findViewById(R.id.displaypanelAllWord_right);

        mChangeDialPadAllWord_vertical_left = (TextImageButton) keyboardRoot
                .findViewById(R.id.displaypanelAllWord_left);

        // a
        mView_v_wordA = (TextImageButton) keyboardRoot.findViewById(R.id.dial_btn_A);
        // b
        mView_v_wordB = (TextImageButton) keyboardRoot.findViewById(R.id.dial_btn_B);
        // c
        mView_v_wordC = (TextImageButton) keyboardRoot.findViewById(R.id.dial_btn_C);
        // d
        mView_v_wordD = (TextImageButton) keyboardRoot.findViewById(R.id.dial_btn_D);
        // e
        mView_v_wordE = (TextImageButton) keyboardRoot.findViewById(R.id.dial_btn_E);
        // f
        mView_v_wordF = (TextImageButton) keyboardRoot.findViewById(R.id.dial_btn_F);
        // g
        mView_v_wordG = (TextImageButton) keyboardRoot.findViewById(R.id.dial_btn_G);
        // h
        mView_v_wordH = (TextImageButton) keyboardRoot.findViewById(R.id.dial_btn_H);
        // i
        mView_v_wordI = (TextImageButton) keyboardRoot.findViewById(R.id.dial_btn_I);
        // j
        mView_v_wordJ = (TextImageButton) keyboardRoot.findViewById(R.id.dial_btn_J);
        // k
        mView_v_wordK = (TextImageButton) keyboardRoot.findViewById(R.id.dial_btn_K);
        // l
        mView_v_wordL = (TextImageButton) keyboardRoot.findViewById(R.id.dial_btn_L);
        // m
        mView_v_wordM = (TextImageButton) keyboardRoot.findViewById(R.id.dial_btn_M);
        // n
        mView_v_wordN = (TextImageButton) keyboardRoot.findViewById(R.id.dial_btn_N);
        // o
        mView_v_wordO = (TextImageButton) keyboardRoot.findViewById(R.id.dial_btn_O);
        // p
        mView_v_wordP = (TextImageButton) keyboardRoot.findViewById(R.id.dial_btn_P);
        // q
        mView_v_wordQ = (TextImageButton) keyboardRoot.findViewById(R.id.dial_btn_Q);
        // r
        mView_v_wordR = (TextImageButton) keyboardRoot.findViewById(R.id.dial_btn_R);
        // s
        mView_v_wordS = (TextImageButton) keyboardRoot.findViewById(R.id.dial_btn_S);
        // t
        mView_v_wordT = (TextImageButton) keyboardRoot.findViewById(R.id.dial_btn_T);
        // u
        mView_v_wordU = (TextImageButton) keyboardRoot.findViewById(R.id.dial_btn_U);
        // v
        mView_v_wordV = (TextImageButton) keyboardRoot.findViewById(R.id.dial_btn_V);
        // w
        mView_v_wordW = (TextImageButton) keyboardRoot.findViewById(R.id.dial_btn_W);
        // x
        mView_v_wordX = (TextImageButton) keyboardRoot.findViewById(R.id.dial_btn_X);
        // y
        // mView_v_wordY = (TextImageButton)
        // numPanel.findViewById(R.id.dial_btn_Y);
        mView_v_wordY = (TextImageButton) keyboardRoot.findViewById(R.id.dial_btn_Y);
        // z
        mView_v_wordZ = (TextImageButton) keyboardRoot.findViewById(R.id.dial_btn_Z);
        // del
        mView_v_word_del = (TextImageButton) keyboardRoot.findViewById(R.id.btn_delete);
    }

    /**
     * 初始化垂直方向全字母键盘
     */
    public void initVerticalAllwordsSkin(SkinVertyData skin, SkinCommonData commonData) {
        CloudDialerActivity.setBgAndScalType(mView_v_wordA, commonData);
        mView_v_wordA.setImageDrawable(skin.abcBgResId[0]);
        if (skin.needSetText.contains("a")) {
            mView_v_wordA.setText("A*");
            mView_v_wordA.setColor(commonData.barTitleColor);
        } else {
            mView_v_wordA.setText("");
        }

        CloudDialerActivity.setBgAndScalType(mView_v_wordB, commonData);
        mView_v_wordB.setImageDrawable(skin.abcBgResId[1]);
        if (skin.needSetText.contains("b")) {
            mView_v_wordB.setText("B");
            mView_v_wordB.setColor(commonData.barTitleColor);
        } else {
            mView_v_wordB.setText("");
        }

        CloudDialerActivity.setBgAndScalType(mView_v_wordC, commonData);
        mView_v_wordC.setImageDrawable(skin.abcBgResId[2]);
        if (skin.needSetText.contains("c")) {
            mView_v_wordC.setText("C");
            mView_v_wordC.setColor(commonData.barTitleColor);
        } else {
            mView_v_wordC.setText("");
        }

        CloudDialerActivity.setBgAndScalType(mView_v_wordD, commonData);
        mView_v_wordD.setImageDrawable(skin.abcBgResId[3]);
        if (skin.needSetText.contains("d")) {
            mView_v_wordD.setText("D");
            mView_v_wordD.setColor(commonData.barTitleColor);
        } else {
            mView_v_wordD.setText("");
        }

        CloudDialerActivity.setBgAndScalType(mView_v_wordE, commonData);
        mView_v_wordE.setImageDrawable(skin.abcBgResId[4]);
        if (skin.needSetText.contains("e")) {
            mView_v_wordE.setText("E");
            mView_v_wordE.setColor(commonData.barTitleColor);
        } else {
            mView_v_wordE.setText("");
        }

        CloudDialerActivity.setBgAndScalType(mView_v_wordF, commonData);
        mView_v_wordF.setImageDrawable(skin.abcBgResId[5]);
        if (skin.needSetText.contains("f")) {
            mView_v_wordF.setText("F");
            mView_v_wordF.setColor(commonData.barTitleColor);
        } else {
            mView_v_wordF.setText("");
        }

        CloudDialerActivity.setBgAndScalType(mView_v_wordG, commonData);
        mView_v_wordG.setImageDrawable(skin.abcBgResId[6]);
        if (skin.needSetText.contains("g")) {
            mView_v_wordG.setText("G");
            mView_v_wordG.setColor(commonData.barTitleColor);
        } else {
            mView_v_wordG.setText("");
        }

        CloudDialerActivity.setBgAndScalType(mView_v_wordH, commonData);
        mView_v_wordH.setImageDrawable(skin.abcBgResId[7]);
        if (skin.needSetText.contains("h")) {
            mView_v_wordH.setText("H");
            mView_v_wordH.setColor(commonData.barTitleColor);
        } else {
            mView_v_wordH.setText("");
        }

        CloudDialerActivity.setBgAndScalType(mView_v_wordI, commonData);
        mView_v_wordI.setImageDrawable(skin.abcBgResId[8]);
        if (skin.needSetText.contains("i")) {
            mView_v_wordI.setText("I");
            mView_v_wordI.setColor(commonData.barTitleColor);
        } else {
            mView_v_wordI.setText("");
        }

        CloudDialerActivity.setBgAndScalType(mView_v_wordJ, commonData);
        mView_v_wordJ.setImageDrawable(skin.abcBgResId[9]);
        if (skin.needSetText.contains("j")) {
            mView_v_wordJ.setText("J");
            mView_v_wordJ.setColor(commonData.barTitleColor);
        } else {
            mView_v_wordJ.setText("");
        }

        CloudDialerActivity.setBgAndScalType(mView_v_wordK, commonData);
        mView_v_wordK.setImageDrawable(skin.abcBgResId[10]);
        if (skin.needSetText.contains("k")) {
            mView_v_wordK.setText("K");
            mView_v_wordK.setColor(commonData.barTitleColor);
        } else {
            mView_v_wordK.setText("");
        }

        CloudDialerActivity.setBgAndScalType(mView_v_wordL, commonData);
        mView_v_wordL.setImageDrawable(skin.abcBgResId[11]);
        if (skin.needSetText.contains("l")) {
            mView_v_wordL.setText("L");
            mView_v_wordL.setColor(commonData.barTitleColor);
        } else {
            mView_v_wordL.setText("");
        }

        CloudDialerActivity.setBgAndScalType(mView_v_wordM, commonData);
        mView_v_wordM.setImageDrawable(skin.abcBgResId[12]);
        if (skin.needSetText.contains("m")) {
            mView_v_wordM.setText("M");
            mView_v_wordM.setColor(commonData.barTitleColor);
        } else {
            mView_v_wordM.setText("");
        }

        CloudDialerActivity.setBgAndScalType(mView_v_wordN, commonData);
        mView_v_wordN.setImageDrawable(skin.abcBgResId[13]);
        if (skin.needSetText.contains("n")) {
            mView_v_wordN.setText("N");
            mView_v_wordN.setColor(commonData.barTitleColor);
        } else {
            mView_v_wordN.setText("");
        }

        CloudDialerActivity.setBgAndScalType(mView_v_wordO, commonData);
        mView_v_wordO.setImageDrawable(skin.abcBgResId[14]);
        if (skin.needSetText.contains("o")) {
            mView_v_wordO.setText("O");
            mView_v_wordO.setColor(commonData.barTitleColor);
        } else {
            mView_v_wordO.setText("");
        }

        CloudDialerActivity.setBgAndScalType(mView_v_wordP, commonData);
        mView_v_wordP.setImageDrawable(skin.abcBgResId[15]);
        if (skin.needSetText.contains("p")) {
            mView_v_wordP.setText("P");
            mView_v_wordP.setColor(commonData.barTitleColor);
        } else {
            mView_v_wordP.setText("");
        }

        CloudDialerActivity.setBgAndScalType(mView_v_wordQ, commonData);
        mView_v_wordQ.setImageDrawable(skin.abcBgResId[16]);
        if (skin.needSetText.contains("q")) {
            mView_v_wordQ.setText("Q");
            mView_v_wordQ.setColor(commonData.barTitleColor);
        } else {
            mView_v_wordQ.setText("");
        }

        CloudDialerActivity.setBgAndScalType(mView_v_wordR, commonData);
        mView_v_wordR.setImageDrawable(skin.abcBgResId[17]);
        if (skin.needSetText.contains("r")) {
            mView_v_wordR.setText("R");
            mView_v_wordR.setColor(commonData.barTitleColor);
        } else {
            mView_v_wordR.setText("");
        }

        CloudDialerActivity.setBgAndScalType(mView_v_wordS, commonData);
        mView_v_wordS.setImageDrawable(skin.abcBgResId[18]);
        if (skin.needSetText.contains("s")) {
            mView_v_wordS.setText("S");
            mView_v_wordS.setColor(commonData.barTitleColor);
        } else {
            mView_v_wordS.setText("");
        }

        CloudDialerActivity.setBgAndScalType(mView_v_wordT, commonData);
        mView_v_wordT.setImageDrawable(skin.abcBgResId[19]);
        if (skin.needSetText.contains("t")) {
            mView_v_wordT.setText("T");
            mView_v_wordT.setColor(commonData.barTitleColor);
        } else {
            mView_v_wordT.setText("");
        }

        CloudDialerActivity.setBgAndScalType(mView_v_wordU, commonData);
        mView_v_wordU.setImageDrawable(skin.abcBgResId[20]);
        if (skin.needSetText.contains("u")) {
            mView_v_wordU.setText("U");
            mView_v_wordU.setColor(commonData.barTitleColor);
        } else {
            mView_v_wordU.setText("");
        }

        CloudDialerActivity.setBgAndScalType(mView_v_wordV, commonData);
        mView_v_wordV.setImageDrawable(skin.abcBgResId[21]);
        if (skin.needSetText.contains("v")) {
            mView_v_wordV.setText("V");
            mView_v_wordV.setColor(commonData.barTitleColor);
        } else {
            mView_v_wordV.setText("");
        }

        CloudDialerActivity.setBgAndScalType(mView_v_wordW, commonData);
        mView_v_wordW.setImageDrawable(skin.abcBgResId[22]);
        if (skin.needSetText.contains("w")) {
            mView_v_wordW.setText("W");
            mView_v_wordW.setColor(commonData.barTitleColor);
        } else {
            mView_v_wordW.setText("");
        }

        CloudDialerActivity.setBgAndScalType(mView_v_wordX, commonData);
        mView_v_wordX.setImageDrawable(skin.abcBgResId[23]);
        if (skin.needSetText.contains("x")) {
            mView_v_wordX.setText("X");
            mView_v_wordX.setColor(commonData.barTitleColor);
        } else {
            mView_v_wordX.setText("");
        }

        CloudDialerActivity.setBgAndScalType(mView_v_wordY, commonData);
        mView_v_wordY.setImageDrawable(skin.abcBgResId[24]);
        if (skin.needSetText.contains("y")) {
            mView_v_wordY.setText("Y");
            mView_v_wordY.setColor(commonData.barTitleColor);
        } else {
            mView_v_wordY.setText("");
        }

        CloudDialerActivity.setBgAndScalType(mView_v_wordZ, commonData);
        mView_v_wordZ.setImageDrawable(skin.abcBgResId[25]);
        if (skin.needSetText.contains("z")) {
            mView_v_wordZ.setText("Z");
            mView_v_wordZ.setColor(commonData.barTitleColor);
        } else {
            mView_v_wordZ.setText("");
        }

        // 竖屏全字母键盘 DialpadEditText
        mDigits_words_vertical.setBackgroundDrawable(skin.vInputResId);
        //mDigits_words_vertical.setTextColor(commonData.barTitleColor);

        CloudDialerActivity.setBgAndScalType(mChangeDialPadAllWord_vertical_right, commonData);
        mChangeDialPadAllWord_vertical_right.setImageDrawable(skin.vAndAbcResId_normal);
        mChangeDialPadAllWord_vertical_right.setColor(commonData.barTitleColor);

        CloudDialerActivity.setBgAndScalType(mChangeDialPadAllWord_vertical_left, commonData);
        mChangeDialPadAllWord_vertical_left.setImageDrawable(skin.vAndAbcResId_normal);
        mChangeDialPadAllWord_vertical_left.setColor(commonData.barTitleColor);

        mAllWordPad.setBackgroundColor(commonData.backgroundColor);

        CloudDialerActivity.setBgAndScalType(mView_v_word_del, commonData);
        mView_v_word_del.setImageDrawable(skin.vabcdelResId);
    }

    /**
     * 预留了每个键的touch,longclick,keypress方法
     */
    private void setupKeypadVertical() {

        //: to del, dulplicate with mT9DialPad
        View.OnTouchListener touchListener = new View.OnTouchListener() {

            @Override
            public boolean onTouch(View v, MotionEvent event) {
                TextImageButton button = (TextImageButton) v;
                int action = event.getAction();
                switch (action) {
                    case MotionEvent.ACTION_DOWN:
                        button.setImageResource(R.drawable.button_pressed);
                        break;
                    case MotionEvent.ACTION_UP:
                    case MotionEvent.ACTION_CANCEL:
                        button.setImageDrawable(mSkin.vAndAbcResId_normal);
                        break;
                }
                return false;
            }
        };

        mChangeDialPadT9_vertical_right.setOnClickListener(this);
        mChangeDialPadT9_vertical_right.setOnTouchListener(touchListener);

        mChangeDialPadT9_vertical_left.setOnClickListener(this);
        mChangeDialPadT9_vertical_left.setOnTouchListener(touchListener);

        // dialpad related
        mDigits.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                return true;
            }
        });
        // mDigits.mOffset += 10;
        //: vert keyboard

        mDigits.addTextChangedListener(mActivity.mTextWatcher);

        mBtnDial.setOnClickListener(this);
        mBtnSendMsg.setOnClickListener(this);
        mBtnSendMsg.setOnLongClickListener(this);

        // num0
        mView_v_num0.setOnClickListener(this);
        mView_v_num0.setOnTouchListener(this);
        mView_v_num0.setOnKeyListener(this);
        mView_v_num0.setOnLongClickListener(this);
        // num1
        mView_v_num1.setOnClickListener(this);
        mView_v_num1.setOnTouchListener(this);
        mView_v_num1.setOnLongClickListener(this);
        mView_v_num1.setOnKeyListener(this);
        // num2
        mView_v_num2.setOnClickListener(this);
        mView_v_num2.setOnTouchListener(this);
        mView_v_num2.setOnKeyListener(this);
        mView_v_num2.setOnLongClickListener(this);
        // num3
        mView_v_num3.setOnClickListener(this);
        mView_v_num3.setOnTouchListener(this);
        mView_v_num3.setOnKeyListener(this);
        mView_v_num3.setOnLongClickListener(this);
        // num4
        mView_v_num4.setOnClickListener(this);
        mView_v_num4.setOnTouchListener(this);
        mView_v_num4.setOnKeyListener(this);
        mView_v_num4.setOnLongClickListener(this);
        // num5
        mView_v_num5.setOnClickListener(this);
        mView_v_num5.setOnTouchListener(this);
        mView_v_num5.setOnKeyListener(this);
        mView_v_num5.setOnLongClickListener(this);
        // num6
        mView_v_num6.setOnClickListener(this);
        mView_v_num6.setOnTouchListener(this);
        mView_v_num6.setOnKeyListener(this);
        mView_v_num6.setOnLongClickListener(this);
        // num7
        mView_v_num7.setOnClickListener(this);
        mView_v_num7.setOnTouchListener(this);
        mView_v_num7.setOnKeyListener(this);
        mView_v_num7.setOnLongClickListener(this);
        // num8
        mView_v_num8.setOnClickListener(this);
        mView_v_num8.setOnTouchListener(this);
        mView_v_num8.setOnKeyListener(this);
        mView_v_num8.setOnLongClickListener(this);
        // num9
        mView_v_num9.setOnClickListener(this);
        mView_v_num9.setOnTouchListener(this);
        mView_v_num9.setOnKeyListener(this);
        mView_v_num9.setOnLongClickListener(this);

        mView_v_num_star.setOnClickListener(this);
        mView_v_num_star.setOnTouchListener(this);
        mView_v_num_star.setOnKeyListener(this);
        mView_v_num_star.setOnLongClickListener(this);

        mView_v_num_del.setOnClickListener(this);
        mView_v_num_del.setOnLongClickListener(this);
        mView_v_num_del.setOnTouchListener(this);

        mView_v_dial.setOnLongClickListener(this);
        mView_v_dial.setOnClickListener(this);
    }

    private void setupKeypadPortraitAllwords() {

        final QwertyKeyListener qwertyKeyListener = QwertyKeyListener.getInstance(false,
                TextKeyListener.Capitalize.NONE);

        mDigits_words_vertical.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                return true;
            }
        });
        mDigits_words_vertical.addTextChangedListener(mActivity.mTextWatcherQwerty);
        mDigits_words_vertical.setKeyListener(qwertyKeyListener);

        View.OnTouchListener touchListener = new View.OnTouchListener() {

            @Override
            public boolean onTouch(View v, MotionEvent event) {
                TextImageButton button = (TextImageButton) v;
                int action = event.getAction();
                switch (action) {
                    case MotionEvent.ACTION_DOWN:
                        if(CloudDialerActivity.isShowChange){
                            button.setImageResource(R.drawable.button_pressed_change);
                        }else{
                            button.setImageResource(R.drawable.button_pressed_add);
                        }

                        break;
                    case MotionEvent.ACTION_UP:
                    case MotionEvent.ACTION_CANCEL:
                        button.setImageDrawable(mSkin.vAndAbcResId_normal);
                        break;
                }
                return false;
            }
        };
        mChangeDialPadAllWord_vertical_right.setOnClickListener(this);
        mChangeDialPadAllWord_vertical_right.setOnTouchListener(touchListener);

        mChangeDialPadAllWord_vertical_left.setOnClickListener(this);
        mChangeDialPadAllWord_vertical_left.setOnTouchListener(touchListener);

        // a
        mView_v_wordA.setOnClickListener(this);
        mView_v_wordA.setOnTouchListener(this);
        mView_v_wordA.setOnKeyListener(this);
        mView_v_wordA.setOnLongClickListener(this);
        // b
        mView_v_wordB.setOnClickListener(this);
        mView_v_wordB.setOnTouchListener(this);
        mView_v_wordB.setOnKeyListener(this);
        mView_v_wordB.setOnLongClickListener(this);
        // c
        mView_v_wordC.setOnClickListener(this);
        mView_v_wordC.setOnTouchListener(this);
        mView_v_wordC.setOnKeyListener(this);
        mView_v_wordC.setOnLongClickListener(this);
        // d
        mView_v_wordD.setOnClickListener(this);
        mView_v_wordD.setOnTouchListener(this);
        mView_v_wordD.setOnKeyListener(this);
        mView_v_wordD.setOnLongClickListener(this);
        // e
        mView_v_wordE.setOnClickListener(this);
        mView_v_wordE.setOnTouchListener(this);
        mView_v_wordE.setOnKeyListener(this);
        mView_v_wordE.setOnLongClickListener(this);
        // f
        mView_v_wordF.setOnClickListener(this);
        mView_v_wordF.setOnTouchListener(this);
        mView_v_wordF.setOnKeyListener(this);
        mView_v_wordF.setOnLongClickListener(this);
        // g
        mView_v_wordG.setOnClickListener(this);
        mView_v_wordG.setOnTouchListener(this);
        mView_v_wordG.setOnKeyListener(this);
        mView_v_wordG.setOnLongClickListener(this);
        // h
        mView_v_wordH.setOnClickListener(this);
        mView_v_wordH.setOnTouchListener(this);
        mView_v_wordH.setOnKeyListener(this);
        mView_v_wordH.setOnLongClickListener(this);
        // i
        mView_v_wordI.setOnClickListener(this);
        mView_v_wordI.setOnTouchListener(this);
        mView_v_wordI.setOnKeyListener(this);
        mView_v_wordI.setOnLongClickListener(this);
        // j
        mView_v_wordJ.setOnClickListener(this);
        mView_v_wordJ.setOnTouchListener(this);
        mView_v_wordJ.setOnKeyListener(this);
        mView_v_wordJ.setOnLongClickListener(this);
        // k
        mView_v_wordK.setOnClickListener(this);
        mView_v_wordK.setOnTouchListener(this);
        mView_v_wordK.setOnKeyListener(this);
        mView_v_wordK.setOnLongClickListener(this);
        // l
        mView_v_wordL.setOnClickListener(this);
        mView_v_wordL.setOnTouchListener(this);
        mView_v_wordL.setOnKeyListener(this);
        mView_v_wordL.setOnLongClickListener(this);
        // m
        mView_v_wordM.setOnClickListener(this);
        mView_v_wordM.setOnTouchListener(this);
        mView_v_wordM.setOnKeyListener(this);
        mView_v_wordM.setOnLongClickListener(this);
        // n
        mView_v_wordN.setOnClickListener(this);
        mView_v_wordN.setOnTouchListener(this);
        mView_v_wordN.setOnKeyListener(this);
        mView_v_wordN.setOnLongClickListener(this);
        // o
        mView_v_wordO.setOnClickListener(this);
        mView_v_wordO.setOnTouchListener(this);
        mView_v_wordO.setOnKeyListener(this);
        mView_v_wordO.setOnLongClickListener(this);
        // p
        mView_v_wordP.setOnClickListener(this);
        mView_v_wordP.setOnTouchListener(this);
        mView_v_wordP.setOnKeyListener(this);
        mView_v_wordP.setOnLongClickListener(this);
        // q
        mView_v_wordQ.setOnClickListener(this);
        mView_v_wordQ.setOnTouchListener(this);
        mView_v_wordQ.setOnKeyListener(this);
        mView_v_wordQ.setOnLongClickListener(this);
        // r
        mView_v_wordR.setOnClickListener(this);
        mView_v_wordR.setOnTouchListener(this);
        mView_v_wordR.setOnKeyListener(this);
        mView_v_wordR.setOnLongClickListener(this);
        // s
        mView_v_wordS.setOnClickListener(this);
        mView_v_wordS.setOnTouchListener(this);
        mView_v_wordS.setOnKeyListener(this);
        mView_v_wordS.setOnLongClickListener(this);
        // t
        mView_v_wordT.setOnClickListener(this);
        mView_v_wordT.setOnTouchListener(this);
        mView_v_wordT.setOnKeyListener(this);
        mView_v_wordT.setOnLongClickListener(this);
        // u
        mView_v_wordU.setOnClickListener(this);
        mView_v_wordU.setOnTouchListener(this);
        mView_v_wordU.setOnKeyListener(this);
        mView_v_wordU.setOnLongClickListener(this);
        // v
        mView_v_wordV.setOnClickListener(this);
        mView_v_wordV.setOnTouchListener(this);
        mView_v_wordV.setOnKeyListener(this);
        mView_v_wordV.setOnLongClickListener(this);
        // w
        mView_v_wordW.setOnClickListener(this);
        mView_v_wordW.setOnTouchListener(this);
        mView_v_wordW.setOnKeyListener(this);
        mView_v_wordW.setOnLongClickListener(this);
        // x
        mView_v_wordX.setOnClickListener(this);
        mView_v_wordX.setOnTouchListener(this);
        mView_v_wordX.setOnKeyListener(this);
        mView_v_wordX.setOnLongClickListener(this);
        // y
        mView_v_wordY.setOnClickListener(this);
        mView_v_wordY.setOnTouchListener(this);
        mView_v_wordY.setOnKeyListener(this);
        mView_v_wordY.setOnLongClickListener(this);
        // z
        mView_v_wordZ.setOnClickListener(this);
        mView_v_wordZ.setOnTouchListener(this);
        mView_v_wordZ.setOnKeyListener(this);
        mView_v_wordZ.setOnLongClickListener(this);
        // del
        mView_v_word_del.setOnClickListener(this);
        mView_v_word_del.setOnKeyListener(this);
        mView_v_word_del.setOnLongClickListener(this);
        mView_v_word_del.setOnTouchListener(this);

    }

    boolean isloadT9 = false;
    boolean isloadAbc = false;

    public void switchKeyboard(boolean isT9, SkinVertyData skin, boolean animGone) {

    	Log.e("eeeeeeeeee","public void switchKeyboard(boolean isT9, SkinVertyData skin, boolean animGone)");
        if (skin == null) {
            skin = new SkinVertyData();
        }
        String path = mPreferenceUtil.getString(PreferenceUtil.CONTACT_KEYBOARD_PACKAGENAME, "local");
        /*
        if (mResource == null) {
            mResource = new GetSkinResource(mActivity);
        }
        */
        mPreferenceUtil.save(PreferenceUtil.IS_T9, isT9);
        
        if (!isloadT9) {
            isloadT9 = true;
            mSkin = ((CloudDialerActivity) getActivity()).mVertySkin;//mResource.getVertT9SkinData(skin, mActivity, path);
            //skin = mSkin;
            initT9Layout(mSkin, mSkinCommonData);
        }
        
        if (!isloadAbc) {
            isloadAbc = true;
            mSkin = ((CloudDialerActivity) getActivity()).mVertySkin2;//mResource.getVertABCSkinData(skin, mActivity, path);
            //skin = mSkin;
            initAllwordsLayout(mSkin, mSkinCommonData);
        }
        

        
        if (isT9) {
        	
            if (!isloadT9) {
                isloadT9 = true;
                mSkin = ((CloudDialerActivity) getActivity()).mVertySkin;//mResource.getVertT9SkinData(skin, mActivity, path);
                //skin = mSkin;
                initT9Layout(mSkin, mSkinCommonData);
            }


            if (mNeedReloadSkin) {
                mNeedReloadSkin = false;
            }

            if (!animGone) {
                if (mAllWordPad != null)
                    mAllWordPad.setVisibility(View.GONE);
                if (mT9DialPad != null)
                    mT9DialPad.setVisibility(View.VISIBLE);
//                mActivity.freshSearchDisplay();//need open
            }

            mDigits.requestFocus();
        } else {
            if (!isloadAbc) {
                isloadAbc = true;
                mSkin = ((CloudDialerActivity) getActivity()).mVertySkin2;//mResource.getVertABCSkinData(skin, mActivity, path);
                //skin = mSkin;
                initAllwordsLayout(mSkin, mSkinCommonData);
            }

            if (mNeedReloadSkin) {
                mNeedReloadSkin = false;
            }

            if (!animGone) {
                if (mT9DialPad != null)
                    mT9DialPad.setVisibility(View.GONE);
                if (mAllWordPad != null){
                    mAllWordPad.setVisibility(View.VISIBLE);
                }
//                mActivity.freshSearchDisplay();//need open
            }

            mDigits_words_vertical.requestFocus();
        }

        mKeyVert.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
            @Override
            public void onGlobalLayout() {
//                initFilterText();//need open
                mKeyVert.getViewTreeObserver().removeGlobalOnLayoutListener(this);
            }
        });

        controlDisplayImageButtonForT9OrAllwords(mKeypadAtRight);
        
    }

    public void controlDisplayImageButtonForT9OrAllwords(boolean isRight) {
        if (isRight) {
            if (mIsT9) {
                mChangeDialPadT9_vertical_right.setVisibility(View.VISIBLE);
                mChangeDialPadT9_vertical_left.setVisibility(View.GONE);
            } else {
                mChangeDialPadAllWord_vertical_right.setVisibility(View.VISIBLE);
                mChangeDialPadAllWord_vertical_left.setVisibility(View.GONE);
            }
        } else {
        	
        	Log.e("eeeeeeeeee","controlDisplayImageButtonForT9OrAllwords");
        	
            if (mIsT9) {
                mChangeDialPadT9_vertical_right.setVisibility(View.GONE);
                mChangeDialPadT9_vertical_left.setVisibility(View.VISIBLE);
            } else {
                mChangeDialPadAllWord_vertical_right.setVisibility(View.GONE);
                mChangeDialPadAllWord_vertical_left.setVisibility(View.VISIBLE);
            }
        }
    }

    @Override
    public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
        if (PreferenceUtil.KEYPAD_AT_RIGHT.equals(key)) {
            mKeypadAtRight = sharedPreferences.getBoolean(key, true);
        }
    }

    @Override
    public void onClick(View v) {
        int viewId = v.getId();
//        if (mActivity.mListStatus == DialerContactsActivity.ListStatus.ENUM_SHOW_CALL_LOG
//                && (mActivity.mBatchOperationType & 1 << Constants.BATCH_OPERATION_DELETE) != 0) {
//            new AlertDialog.Builder(mActivity)
//                    .setMessage("批量删除通话记录时不可查询!")
//                    .setNegativeButton("确定", null)
//                    .create().show();
//            return;
//
//        } else {
            if (mViewIdKeyCodeMap != null && mViewIdKeyCodeMap.containsKey(viewId)) {
                v.performHapticFeedback(HapticFeedbackConstants.KEYBOARD_TAP);
                keyPressed(mViewIdKeyCodeMap.get(viewId));
                
                
                
                return;
            }
//        }
        switch (viewId) {
            case R.id.displaypanelT9_right:
            case R.id.displaypanelT9_left:
            case R.id.displaypanelAllWord_right:
            case R.id.displaypanelAllWord_left:

                // TODO 如果是批处理“+”键不起作用
                if(CloudDialerActivity.mBatchOperationType != 0 ){//findViewById(R.id.ll_batck_opertion).getVisibility() == View.VISIBLE){
                    mActivity.changePage(true);
                	return;
                }
                if (mActivity.mListStatus == CloudDialerActivity.ListStatus.ENUM_SHOW_CLOUD_CONTACT) {
                    mActivity.showPlusButtonWindow(true);
                } else{
                    mActivity.showPlusButtonWindow(false);
                }
                break;
            case R.id.btn_delete:
            case R.id.dial_btn_delete:
                v.performHapticFeedback(HapticFeedbackConstants.KEYBOARD_TAP);
                keyPressed(KeyEvent.KEYCODE_DEL);
                break;
            case R.id.dial_btn_dial:
            case R.id.dial_btn_send_msg:
                mActivity.onClick(v);
                break;
            default:
                break;
        }
    }

    private void keyPressed(int keyCode) {
        KeyEvent event = new KeyEvent(KeyEvent.ACTION_DOWN, keyCode);
        if (mIsT9) {
            mDigits.onKeyDown(keyCode, event);
        } else {
            mDigits_words_vertical.onKeyDown(keyCode, event);
            
            Log.e("mDigits_words_vertical","keyPressed");
        }
    }

    @Override
    public boolean onLongClick(View v) {
        switch (v.getId()){
            case R.id.dial_btn_delete:
                if (mDigits.getText().length() > 0) {
                    mDigits.setText("");
                }
                break;
            case R.id.btn_delete:
                if (mDigits_words_vertical.getText().length() > 0) {
                    mDigits_words_vertical.setText("");
                }
                break;
            case R.id.dial_btn_A:
                keyPressed(KeyEvent.KEYCODE_STAR);
                break;
            case R.id.dial_btn_xing:
                keyPressed(KeyEvent.KEYCODE_POUND);
                break;
            case R.id.dial_btn_num0:
                keyPressed(KeyEvent.KEYCODE_PLUS);
                break;
            default:
                break;
        }
        return true;
    }

    public String getFilterText() {
        String filterText = null;
        if (mIsT9 && mDigits != null) {
            filterText = mDigits.getText().toString();
        } else if (mDigits_words_vertical != null) {
            filterText = mDigits_words_vertical.getText().toString();
        }
        return filterText;
    }

    public String getNumFilterText() {
        String filterText = "";
        if (mIsT9 && mDigits != null) {
            filterText = mDigits.getText().toString();
        }
        return filterText;
    }


    /**
     * 单独设置T9键盘的搜索字
     * @param text
     */
    public void setSearchTextT9(String text){

        Log.d("textChanged_search","========  setSearchTextT9  =======");

        if(text != null){
            if (text.length() <= 20) {
                if(mDigits != null){
                    mDigits.setText(text);
                    mDigits.setSelection(text.length());
                }
            }
        }
    }

    /**
     * 单独设置字母键盘的搜索字
     * @param text
     */
    public void setSeaechTextAllWord(String text){
        if(text != null){
            if(mDigits_words_vertical != null){
                mDigits_words_vertical.setText(text);
                mDigits_words_vertical.setSelection(text.length());
                Log.d("mDigits_words_vertical",text);

            }
        }
    }

    /**
     * 设置搜索字
     * @param text
     */
    public void setFilterText(String text) {

        Log.d("textChanged_search","========  text  ======= " + text);

        if (mIsT9) {
            if(text != null){
                if (text.length() <= 20) {
                    if(mDigits != null){
                        mDigits.setText(text);
                        mDigits.setSelection(text.length());
                    }
                }
            }
        } else {
            if(text != null){
                if(mDigits_words_vertical != null){
                    mDigits_words_vertical.setText(text);
                    mDigits_words_vertical.setSelection(text.length());
                    Log.d("mDigits_words_vertical",text);

                }
            }
        }
    }

    
    public void enableInput(boolean enabled)
    {
    	if( mDigits_words_vertical != null )
    	{
    		mDigits_words_vertical.setEnabled(enabled);
    	}
    }
    
    
    
    
    
    
    @Override
    public boolean onTouch(View v, MotionEvent event) {
        return false;
    }

    @Override
    public boolean onKey(View v, int keyCode, KeyEvent event) {
        return false;
    }

}